/**
 * This class represents a set of actions that a Schwimmen game might need to call
 * in order to play.
 * @author Chris Fraser, Jean-Luc Richard
 *
 */
public class SchwimmenActions
{
        /**
         * Object for the set of "card" actions
         */
        private CardGameActions cardActions;
        
        /**
         * Object for the deck of cards
         */
        private SchwimmenCardDeck deck;
        
        /**
         * Constructor method
         */
        public SchwimmenActions()
        {
                this.deck = new SchwimmenCardDeck();
                this.cardActions = new CardGameActions();
                this.cardActions.shuffleDeck(this.deck);
        }
        
        /**
         * Update the table with 3 new cards drawn from the deck.
         * @param board A String[] of the 3 cards on the table
         */
        public void updateTable(String[] board, String[][] hands, int numPlayers)
        {
        	//Draw three cards and replace table with it
        	for(int i=0; i < board.length; i++)
        	{
        		String temp = this.cardActions.drawCard(this.deck);
        		String[] playerHands = new String[hands.length*numPlayers + board.length];
        		
        		if(temp == null)
        		{
        			//Re-shuffle a new deck and remove from the deck all cards in players' hands
        			this.deck = new SchwimmenCardDeck();
        			this.cardActions.shuffleDeck(this.deck);
        			
        			for(int j=0; j < numPlayers; i++)
        			{
        				for(int k=0; k < hands.length; k++)
        				{
        					playerHands[(j*hands.length)+k] = hands[j][k];
        				}
        			}
        			
        			//... and remove cards from the table if any
        			for(int j=0; j < i; j++)
        			{
        				playerHands[(numPlayers*hands.length) + j] = board[j];
        			}
        			
        			this.deck.removeCards(playerHands);
        			
        			//Now we can draw from the new re-shuffled deck
        			temp = this.cardActions.drawCard(this.deck);
        		}

        		board[i] = temp;
        	}
          
        	//If you're drawing the last card, reshuffle deck by creating a new deck
        	//and subtracting the deck from the hands and the table.
          
        	//Replace table by the drawn cards
        }
      
        /**
         * This method draws a new hand and returns a String[] of these cards
         * @return The new hand drawn from the deck
         */
        public String[] newHand() 
        {
        	return new String[] {this.cardActions.drawCard(this.deck), 
        		this.cardActions.drawCard(this.deck),
        		this.cardActions.drawCard(this.deck)};
        }
}
